import qrcodeTerminal from "qrcode-terminal";
import { ScanStatus, log } from "@juzi/wechaty";
import { SocketTypeEnum } from "../websocket/socketTypeEnum.js";

const mScan = (qrcode, status, sendMessageToAll) => {
  console.log("进入扫码");
  sendMessageToAll({ Type: SocketTypeEnum.Console, Data: "进入扫码" });
  if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) {
    const qrcodeImageUrl = [
      "https://wechaty.js.org/qrcode/",
      encodeURIComponent(qrcode),
    ].join("");
    sendMessageToAll({ Type: SocketTypeEnum.QRCode, Data: qrcode });
    qrcodeTerminal.generate(qrcode, { small: true });
  } else {
    log.info("StarterBot", "onScan: %s(%s)", ScanStatus[status], status);
  }
};
export default mScan;
// module.exports = mScan;
